<html>
  <head>
    <title>Stacked Area Chart</title>
    <script type="text/javascript" src="../../protovis.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

var data = pv.range(4).map(function()
        pv.range(0, 10, .1).map(function(x) {
            return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
          }));

var i = -1, // mouseover index
    w = 400,
    h = 200,
    x = pv.Scale.linear(0, 9.9).range(0, w),
    y = pv.Scale.linear(0, 14).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(30)
    .top(5)
    .events("all")
    .event("mousemove", pv.Behavior.point(Infinity).collapse("y"));

var area = vis.add(pv.Layout.Stack)
    .layers(data)
    .x(function(d) x(d.x))
    .y(function(d) y(d.y))
  .layer.add(pv.Area);

/* A transparent overlay to avoid label clipping. */
vis.add(pv.Panel)
    .data(data)
  .add(pv.Area)
    .extend(area)
    .fillStyle(null)
    .event("point", function() (i = this.index, this.parent))
    .event("unpoint", function() (i = -1, this.parent))
  .add(pv.Rule)
    .visible(function() i == this.index)
    .strokeStyle("black")
  .anchor("top").add(pv.Rule)
    .width(6)
    .anchorTarget()
  .anchor("right").add(pv.Label)
    .text(function(d) d.y.toFixed(3));

vis.add(pv.Rule)
    .data(x.ticks())
    .visible(function(d) d)
    .left(x)
    .strokeStyle("rgba(128,128,128,.1)")
  .anchor("bottom").add(pv.Label)
    .text(function(d) d.toFixed());

vis.add(pv.Rule)
    .data(y.ticks())
    .visible(function() !(this.index % 2))
    .bottom(y)
    .strokeStyle(function(d) d ? "rgba(128,128,128,.2)" : "#000")
  .anchor("left").add(pv.Label)
    .text(function(d) d.toFixed());

vis.render();

    </script>
  </body>
</html>
